package com.jemframework.utils.stringformatter;

import java.util.ArrayList;
import java.util.List;

public class xxxYyy_StringFormatter extends AbstractStringFormatter {

  public xxxYyy_StringFormatter() {
    super();
  }

  protected int computeEndPosition(int i, Integer[] positions, String string) {
    if (i < positions.length - 1) {
      return positions[i + 1];
    } else {
      return string.length();
    }
  }

  protected Integer[] getTokensStartPositions(String string) {

    List<Integer> positions = new ArrayList<Integer>();

    int i = 0;

    positions.add(i);

    for (char ch : string.toCharArray()) {
      if (Character.isUpperCase(ch)) {
        positions.add(i);
      }
      i++;
    }

    return positions.toArray(new Integer[positions.size()]);
  }

  protected void formatToken(StringBuffer out, String token, int tokens, int index) {
    if (index == 0) {
      out.append(token);
      return;
    }

    out.append(Character.toUpperCase(token.charAt(0)));
    out.append(token.substring(1, token.length()));
  }
}
